package com.jianZhiOffer;

public class Solution44 {
    public static void main(String[] args) {
        findNthDigit(1000000000);
    }

    public static int findNthDigit(int n) {
        int digits = 1;
        long base = 9;
        while (n - digits * base > 0) {
            n -= digits * base;
            digits++;
            base *= 10;
        }
        int num = (int) Math.pow(10, digits - 1) + (n - 1) / digits;
        int index = n % digits;
        if (index == 0) index = digits;
        for (int i = index; i < digits; i++) {
            num /= 10;
        }
        return num % 10;
    }
}
